############################ # Tkinter Pole Rombu # # ver. 2,0 # ############################ from tkinter import * #inicjalizacja zmiennych win = Tk() win.title("Pole Rombu ver. 2.0") var1 = IntVar() var2 = IntVar() var3 = IntVar() var4 = IntVar() #definicja funkcji def Przekątne_Rombu(): d1 = e1.get() #pobierz i przypisz dane z pola1 i pola2 d2 = e2.get() calculation = 0.5 * float(d1) * float(d2) entryResult.config(text=calculation) def Wysokość_i_długość_Rombu(): a = e3.get() #pobierz i przypisz dane z pola1 i pola2 h = e4.get() calculation = float(a) * float(h) entryResult2.config(text=calculation) # --- tkinter Window --- win.minsize(width=350, height=350) #minimalna wielkość okna # labels - etykiety labelInfo = Label(win, text="Ten program liczy pole rombu. \n \n Kalkulacja bazująca na przekątnych rombu:") labelInfo.grid(row=0, column=0, columnspan=2) label = Label(win, text=" Podaj długości przekątnych:") label.grid(row=1, column=1) labeld1 = Label(win, text=" d1 :") labeld1.grid(row=3, column=0, sticky=E) # Entry field- pole wprowadzania i wyświetlania e1 = Entry(win, textvariable=var1) e1.grid(row=3, column=1) labeld2 = Label(win, text=" d2 :") labeld2.grid(row=4, column=0, sticky=E) e2 = Entry(win, textvariable=var2) e2.grid(row=4, column=1) labelResult = Label(win, text=" Pole Rombu :") labelResult.grid(row=6, column=0) entryResult = Label(win) entryResult.grid(row=6, column=1, columnspan=2, sticky=W) # Button - guzik uruchamiający funkcję parametrem command button = Button(win, text="Kalkulacja", command=Przekątne_Rombu) button.grid(row=5, column=1,) # labels - etykiety labelInfo = Label(win, text=" \n Kalkulacja bazująca na długości podstawy oraz wysokości rombu:") labelInfo.grid(row=7, column=0, columnspan=2) label = Label(win, text=" Podaj długość i wysokość rombu:") label.grid(row=8, column=1) labela = Label(win, text=" a :") labela.grid(row=10, column=0, sticky=E) # Entry field- pole wprowadzania i wyświetlania e3 = Entry(win, textvariable=var3) e3.grid(row=10, column=1) labelh = Label(win, text=" h :") labelh.grid(row=11, column=0, sticky=E) e4 = Entry(win, textvariable=var4) e4.grid(row=11, column=1) labelResult = Label(win, text=" Pole Rombu :") labelResult.grid(row=13, column=0) entryResult2 = Label(win) entryResult2.grid(row=14, column=1, columnspan=2, sticky=W) # Button - guzik uruchamiający funkcję parametrem command button = Button(win, text="Kalkulacja", command=Wysokość_i_długość_Rombu) button.grid(row=12, column=1,) # - window loop - główna pętla okna ( bez niej okienko pojawi sie na ułamek sekundy) win.mainloop()